﻿using System;

namespace Abp0713Demo
{
    public static class DateTimeHelper
    {
        /// <summary>
        /// 初始时间
        /// </summary>
        public static readonly DateTime InitTime = new DateTime(1970, 1, 1);
        // DateTime --> long
        public static long ConvertDataTimeToLong(this DateTime dt)
        {
            DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(InitTime);
            TimeSpan toNow = dt.Subtract(dtStart);
            long timeStamp = toNow.Ticks;
            timeStamp = timeStamp/10000;
            return timeStamp;
        }
        // long --> DateTime
        public static DateTime ConvertLongToDateTime(long d)
        {
            DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(InitTime);
            long lTime = d*10000;
            TimeSpan toNow = new TimeSpan(lTime);
            DateTime dtResult = dtStart.Add(toNow);
            return dtResult;
        }
    }
}